package day_2022_9_to_12.Day;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author haomin
 * @date 2022/09/05 18:20
 **/
public class Day3_5_Offer54_MaxDepth {
    class Solution {
        public int maxDepth(TreeNode root) {
            if(root == null) return 0;
            return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
        }
    }
    class Solution2 {
        public int maxDepth(TreeNode root) {
            if(root == null) return 0;
            int ans = 0;
            Queue<TreeNode> q = new LinkedList<>();
            q.offer(root);
            while(!q.isEmpty()){
                int size = q.size();
                for(int i = 0; i < size; ++i){
                    TreeNode cur = q.poll();
                    if(cur.left != null) q.offer(cur.left);
                    if(cur.right != null) q.offer(cur.right);
                }
                ans++;
            }
            return ans;
        }
    }
}